/*
 * SOPDetectorTool.h
 *
 *  Created on: Mar 18, 2013
 *      Author: shuai
 */

#ifndef SOPDETECTORTOOL_H_
#define SOPDETECTORTOOL_H_

#include <iostream>
#include <vector>
#include <fstream>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/sax/HandlerBase.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMNodeIterator.hpp>
#include <xercesc/dom/DOMNodeList.hpp>
#include <xercesc/dom/DOMNamedNodeMap.hpp>
#include <xercesc/dom/DOMException.hpp>
#include "SOPDetectorDocRoot.h"
#include "SOPInterval.h"
#include "SOPDetectorState.h"
#include "StringToNum.h"

using namespace xercesc;

class SOPDetectorTool
{
	public:
		SOPDetectorTool();
		~SOPDetectorTool();

	private:
		/* Input file */
		std::string inputFile;

		/* Output file */
		std::string outputFile;

		/* Input stream */
		std::ifstream in;

		/* Output stream */
		std::ofstream out;

		/* DOM XML parser */
		XercesDOMParser * domParser;

		/* DOMDocument */
		//DOMDocument * xmlDocument;

		/* data stored in SOPDetectorDocRoot object */
		SOPDetectorDocRoot * doc;

	public:
		void SetInputFile(std::string fileName);

		void SetOutputFile(std::string fileName);

		void SetInputOutput(std::string inputFileName,
							std::string outputFileName);

		void Parse();

	private:
		void InitializeXercesSystem();

		void ParseXML();

		void CleanUpXercesSystem();

		void PrepareParser();

		void StartParseXML();

		DOMElement * ParseDocRootDetector();

		void ParseIntervalInfo(DOMElement* detectorNode);

		std::string FindAttribute(DOMNamedNodeMap * attributes,
									std::string name);

		void OpenInputStream();

		void CloseInputStream();

		void OpenOutputStream();

		void CloseOutputStream();

		void WriteDataToFile();
};

#endif /* SOPDETECTORTOOL_H_ */
